package net.int0r.gscore.connector;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.apache.log4j.Logger;
import org.json.JSONArray;

import net.int0r.gscore.gobjects.Stamp;
import net.int0r.gscore.util.GJSONObject;
import net.int0r.gscore.util.GowallaConnector;

public class UserStampConnector {
	private static Logger log = Logger.getLogger(UserStampConnector.class);
	
	public static ArrayList<Stamp> getStampsForUser(String userName, int limit) {
		ArrayList<Stamp> stamps = new ArrayList<Stamp>();
		ArrayList<NameValuePair> urlParms = new ArrayList<NameValuePair>();
		urlParms.add(new BasicNameValuePair("limit", ""+limit));
		GJSONObject jsobj = GowallaConnector.getJSONObj(urlParms, "/users/"+userName+"/stamps");
		log.debug(jsobj.names());
		try {
			JSONArray js2 = jsobj.getJSONArray("stamps");
			for(int i=0; i<js2.length(); i++) {
				stamps.add(new Stamp(new GJSONObject(js2.getJSONObject(i).toString())));
			}
		}
		catch(Exception ex) {
			
		}
		return stamps;
	}
}
